package com.akkainaction.tool.io.tcp.client;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.io.TcpMessage;
import akka.util.ByteString;
import com.akkainaction.tool.io.tcp.event.MyAck;

import java.util.concurrent.TimeUnit;

public class StartTcpClient {

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys");
        ActorRef tcpClientDemo = system.actorOf(Props.create(TcpClientDemo.class), "tcpClientDemo");
        //向server端发送消息，需要包装成TcpMessage，这里需要等待几秒钟，为的是建立连接。
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        MyAck ack = new MyAck(23);
        tcpClientDemo.tell(TcpMessage.write(ByteString.fromString("HelloAkka111"),ack),ActorRef.noSender());
    }
}
